//
//  ThreadDAO.h
//
//  Created by djr on 16/2/17.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

typedef void (^handle_block_t)(void (^handle_callback_block_t)(void));

@interface ThreadDAO : NSObject
/** 全局并行队列 */
@property (strong, readonly, nonatomic) dispatch_queue_t globalQueue;
/** 并行队列 */
@property (strong, readonly, nonatomic) dispatch_queue_t concurrentQueue;
/** 串行队列 */
@property (strong, readonly, nonatomic) dispatch_queue_t serialQueue;
/** 主线程 */
@property (strong, readonly, nonatomic) dispatch_queue_t mainQueue;

/** 创建GCD子线程 */
+ (void)executeInGlobalQueue:(dispatch_block_t)block;
+ (void)executeInGlobalQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec;
/** 创建GCD自定义子线程 */
+ (void)executeInCustomGlobalQueue:(dispatch_queue_t)globalQueue block:(dispatch_block_t)block;
/** 创建GCD同步自定义子线程 */
+ (void)executeInSyncCustomGlobalQueue:(dispatch_queue_t)globalQueue block:(dispatch_block_t)block;
+ (void)executeInCustomGlobalQueue:(dispatch_queue_t)globalQueue block:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec;
/** 创建GCD主线程 */
+ (void)executeInMainQueue:(dispatch_block_t)block;
+ (void)executeInMainQueue:(dispatch_block_t)block afterDelaySecs:(NSTimeInterval)sec;
/** 创建GCD同步主线程（注意：在主线程调用会引起死锁） */
+ (void)executeInSyncMainQueue:(dispatch_block_t)block;

/** 创建线程 */
+ (void)executeInGlobalQueue:(dispatch_block_t)gBlock mainQueue:(dispatch_block_t)mBlock;
+ (void)executeInCustomGlobalQueue:(dispatch_queue_t)globalQueue globalBlock:(dispatch_block_t)gBlock mainQueue:(dispatch_block_t)mBlock;

/** 创建有限制的线程 线程数量为5 */
+ (void)executeInGlobalLimitQueue:(dispatch_block_t)gBlock mainQueue:(dispatch_block_t)mBlock;
/** 加入串行异步等待线程 */
+ (void)executeInWaitQueueWithKey:(NSString *)key handler:(handle_block_t)handler completion:(dispatch_block_t)completion;

/** 挂起线程 */
+ (void)suspend:(dispatch_queue_t)queue;

/** 恢复线程(挂起线程后，必须在销毁之前恢复线程) */
+ (void)resume:(dispatch_queue_t)queue;

@end
NS_ASSUME_NONNULL_END
